﻿using Abp.AspNetCore.Mvc.Controllers;
using Abp.Domain.Repositories;
using Batman.Core;
using Batman.Jianbei.Forum.Areas.Forum.Converts;
using Batman.Jianbei.Forum.Core.Consts;
using Batman.Jianbei.Forum.Core.Domains.Posts;
using Batman.Jianbei.Forum.Core.Domains.Users;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System;
using System.Linq;

namespace Batman.Jianbei.Forum.Areas.Admin
{
    [Area(RouteNames.Admin)]
    public class PostController : AbpController
    {
        public IRepository<Post, string> PostRepo { get; set; }

        public IRepository<PostComment, string> CommentRepo { get; set; }

        public IRepository<WeixinUser, string> WxUserRepo { get; set; }

        /// <summary>
        /// 获取帖子详细
        /// </summary>
        /// <param name="postId"></param>
        /// <returns></returns>
        public IActionResult Detail(string postId)
        {
            var query = PostRepo.GetQuery().Where(t => t.Id == postId);
            query = query.Include(t => t.Topic).ThenInclude(t => t.Partition);
            query = query.Include(t => t.Imgs);
            query = query.Include(t => t.WxUser);

            var detail = query.Select(t => t.ToPostFlowItem()).FirstOrDefault();

            return Json(detail);
        }

        public IActionResult Comments(string postId)
        {
            var query = CommentRepo.GetQuery().Where(t => !t.IsDeleted && t.PostId == postId);

            var weixinUserQuery = WxUserRepo.GetQuery();

            throw new NotImplementedException();

        }
    }
}
